home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / areuh.tar / areuh / assembler / alist.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  4KB  |  193 lines

  1. /*
  2.  * Authors :
  3.  *   Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet)
  4.  *   Janick TAILLANDIER
  5.  *
  6.  * This program can be freely used or distributed as long as this
  7.  * note is kept.
  8.  *
  9.  * This program is provided "as is".
  10.  */
  11.  
  12. /******************************************************************************
  13.  
  14.                 AREUH ASSEMBLER
  15.  
  16.                 LISTING FILE PROCESSING
  17.  
  18.  
  19. l_init, l_flush, l_print, l_new_page, l_line, l_page
  20.  
  21. ******************************************************************************/
  22.  
  23. #include "aglobal.h"
  24.  
  25. int l_line, l_page ;
  26. void l_new_page (), l_page_header () ;
  27.  
  28. uchar fstdout [] = "stdout" ;
  29.  
  30.  
  31. /******************************************************************************
  32.  
  33.                     L_INIT
  34.  
  35.  
  36. synopsis : l_init()
  37. description : initiates the listing mechanism, if necessary.
  38.  
  39. ******************************************************************************/
  40.  
  41. void l_init()
  42. {
  43.     uchar tmp [MAXLEN+1] ;
  44.  
  45.     switch (cntlist)
  46.     {
  47.     case 0 :
  48.         break ;
  49.     case 1 :
  50.         fd_l = stdout ;
  51.         break ;
  52.     case 2 :
  53.         dfl_extension (tmp, fsource, "al") ;
  54.         look_obj (flisting, tmp) ;
  55.         if ((fd_l = fopen (flisting, "w")) == NULL)
  56.         error (ERROPN, flisting) ;
  57.         break ;
  58.     }
  59.     l_page = 0 ;
  60.     if (cntlist) l_page_header () ;
  61. }
  62.  
  63.  
  64. /******************************************************************************
  65.  
  66.                     L_FLUSH
  67.  
  68.  
  69. synospsis : void l_flush ()
  70. description : forces a new page, then closes the listing file if necessary.
  71.  
  72. ******************************************************************************/
  73.  
  74. void l_flush()
  75. {
  76.     if (cntlist==0)    return ;
  77.     l_new_page(0) ;
  78.     if (cntlist == 2)
  79.     {
  80.     if (fclose (fd_l))  error (ERRCLO, flisting) ;
  81.     }
  82. }
  83.  
  84.  
  85. /******************************************************************************
  86.  
  87.                     L_PRINT
  88.  
  89.  
  90.  
  91. synopsis : void l_print (pc, code, msg, flags)
  92.        saddr pc
  93.        uchar *code, *msg
  94.        int flags
  95. description : prints a line on the listing file.
  96.           The line may contain  - program counter value    F_PC
  97.                     - line number        F_LN
  98.                     - generated code        F_GC
  99.                     - text line         F_TL
  100.           according the "flags" variable.
  101.           E.g. : to print pc and generated code, call
  102.              l_print(pc, gen_code, "", F_PC + F_GC)
  103.  
  104. ******************************************************************************/
  105.  
  106. void l_print (address, code, msg, flags)
  107. saddr address ;
  108. uchar *code, *msg ;
  109. int flags ;
  110. {
  111.     uchar line[MAXLEN+1], tmp[MAXLEN+1] ;
  112.  
  113.     if (!(cntlist))    return ;
  114.  
  115.     if (flags==F_TL)
  116.     {
  117.     sprintf (line, "%.79s", msg) ;
  118.     }
  119.     else
  120.     {
  121.     if (flags & F_LN) sprintf (line, "%04d ", linenb) ;     /* 5 chars */
  122.     else strcpy (line, "     ") ;
  123.  
  124.     if (flags & F_PC)                    /* 6 chars */
  125.     {
  126.         hex5 (tmp, address) ;
  127.         strcat (line, tmp) ;
  128.         strcat (line, " ") ;
  129.     }
  130.     else strcat (line, "      ") ;
  131.  
  132.     if (flags & F_GC)                    /* 9 chars */
  133.     {
  134.         sprintf (tmp, "%-9.8s", code) ;
  135.         strcat (line, tmp) ;
  136.     }
  137.     else strcat (line, "         ") ;
  138.  
  139.     if (flags & F_TL)                       /* 60 chars */
  140.     {
  141.         sprintf (tmp, "%.60s", msg) ;
  142.         strcat (line, tmp) ;
  143.     }
  144.     }
  145.  
  146.     if (l_line==(page_size-6))     l_new_page (1) ;
  147.  
  148.     fprintf (fd_l, "%s\n", line) ;
  149.     if (ferror (fd_l))
  150.     error (ERRWRT, (cntlist == 1) ? fstdout : flisting) ;
  151.     l_line++ ;
  152.  
  153.     if (strlen(code)>8)
  154.     l_print (address+8, code+8, "", F_PC + F_GC) ;
  155. }
  156.  
  157.  
  158.  
  159. /******************************************************************************
  160.  
  161.                   L_NEW_PAGE
  162.  
  163.  
  164. synopsis : void l_new_page (flag)
  165.        int flag
  166. description : forces a new page on listing file, and if flag # 0, prints a
  167.           header composed by page number, l_stitle and l_title.
  168.  
  169. ******************************************************************************/
  170.  
  171. void l_new_page (flag)
  172. int flag ;
  173. {
  174.     if (!(cntlist)) return ;
  175.  
  176.     for (; l_line<page_size; l_line++)     fprintf (fd_l, "\n") ;
  177.     if (ferror (fd_l))
  178.     error (ERRWRT, (cntlist == 1) ? fstdout : flisting) ;
  179.  
  180.     if (flag) l_page_header () ;
  181. }
  182.  
  183.  
  184. void l_page_header ()
  185. {
  186.     fprintf (fd_l, "Page %03d           %.60s\n", ++l_page, l_title) ;
  187.     fprintf (fd_l, "AREUH ASS. V2.4    %.60s\n", l_stitle) ;
  188.     fprintf (fd_l, "\n") ;
  189.     l_line = 3 ;
  190.     if (ferror (fd_l))
  191.     error (ERRWRT, (cntlist == 1) ? fstdout : flisting) ;
  192. }
  193.